package com.yj.suncity.activity.shouye;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import com.yj.suncity.R;
import com.yj.suncity.async.AsyncTaskUtil;
import com.yj.suncity.async.AsyncTaskUtil.ResultCallBack;
import com.yj.suncity.constant.URLCon;
import com.yj.suncity.utis.ToastUtil;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class CityHelpSubmitCommentActivity extends Activity {

	private Context context;
	private String userId;
	private String helpId;
	private EditText mEdt_comment;
	private List<NameValuePair> pairs = new ArrayList<NameValuePair>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_city_help_submit_comment);
		context = this;
		userId = getIntent().getStringExtra("userid");
		helpId = getIntent().getStringExtra("helpid");
		findView();
	}

	private void findView() {
		mEdt_comment = (EditText) findViewById(R.id.edt_comment_content);

	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnHeadBack:
			this.finish();
			break;
		case R.id.btn_submit_comment:
			String comment_content = mEdt_comment.getText().toString();
			if (comment_content.equals("")) {
				ToastUtil.ShowToast(context, "请输入评论内容！");
				return;
			}
			pairs.clear();
			pairs.add(new BasicNameValuePair("action", "publishcomment"));
			pairs.add(new BasicNameValuePair("userid", userId));
			pairs.add(new BasicNameValuePair("id", helpId));
			pairs.add(new BasicNameValuePair("commentusercontent",
					comment_content));
			submitComment();
			break;
		default:
			break;
		}

	}

	private void submitComment() {
		String path = URLCon.同城帮帮;
		AsyncTaskUtil asyncTaskUtil = new AsyncTaskUtil(context, pairs, null,
				false, null, true, "正在提交......", new ResultCallBack() {
					@Override
					public void JSONResult(JSONObject jsonObject) {
						if (jsonObject.optString("success").equals("1")) {
							ToastUtil.ShowToast(context,"评论成功！");
							setResult(1);
							CityHelpSubmitCommentActivity.this.finish();
						} else {
							ToastUtil.ShowToast(context,
									jsonObject.optString("msg"));
						}
					}
				});
		asyncTaskUtil.execute(path);
	}

}
